<template>
  <div class="tabbarItem" @click="itemClick">
    <div v-if="!isActive">
      <slot name="item-img"></slot>
    </div>
    <div v-else>
      <slot name="item-img-active"></slot>
    </div>
    <div :style="styleActive">
      <slot name="item-text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabbarItem",
  props:{
    path:String,
    styleColor:{
      type:String,
      default:'red'
    }
  },
  computed:{
    isActive(){
      return this.$route.path.indexOf(this.path) !== -1
    },
    styleActive(){
      return this.isActive ? {color:this.styleColor}:{}
    }
  },
  methods:{
    itemClick(){
      this.$router.replace(this.path)
    }
  }
};
</script>

<style>
.tabbarItem {
  flex: 1;
}
.tabbarItem img {
  margin-top: 3px;
  vertical-align: middle;
  height: 24px;
  width: 24px;
}
</style>